<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    var p = new Promise(function (resolve, reject) {
        // resolve(1);

        setTimeout(function () {
            resolve(1);
        }, 2000);
    })
    console.log(p);

    var p2 = new Promise(function (resolve, reject) {
        // resolve(1);

        setTimeout(function () {
            resolve("hello");
        }, 2000);
    })
    console.log(p2);

    // p.then(function(val){},function(err){})
    // p.catch(function(){}); //  p.then(null,function(err){})

    p.then(v => v).catch(err => { throw err });

    // p1
    p.then(v => {
        console.log(v);
        return 2;
    }).then(v => {
        console.log(v);
        // return 3;
        return p2;
    }).then(v => {
        console.log(v);
    }).catch(err => {
        throw err;
    }).finally(() => {

    })


    Promise.all([p1, p2, p3]).then(list => {

    }).catch(err => {

    })

    Promise.race([p1, p2, p3]).then(list => {

    }).catch(err => {

    })


    Promise.resolve(1);  // 同步
    Promise.resolve({  // 异步
        then(resolve, reject) {


        }
    });
    Promise.reject(2);




</script>

</html>